def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def nearest_prime(word):
    number_dict = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }

    if word in number_dict:
        number = number_dict[word]
        if 100 <= number <= 999:
            i = 0
            while True:
                if is_prime(number - i) and number - i >= 100:
                    return number - i
                elif is_prime(number + i) and number + i <= 999:
                    return number + i
                i += 1
        else:
            return "Wrong input"
    else:
        return "Wrong input"
input_words = input().split()
if len(input_words) == 3:
    result = nearest_prime(input_words[0])
    print(result)
else:
    print("Wrong input")
